package com.codefish.framework.spring.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日志对象
 *
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/09/23 下午 04:28
 */
public  class Logger {
    private final Class<?> clazz;


    protected Logger(Class<?> clazz) {
        this.clazz = clazz;
    }

    public void info(String format, Object... args) {
        String content = String.format(format, args);
        StringBuilder sb = new StringBuilder(timeTag());
        sb.append(" ")
                .append(levelTag())
                .append(" ")
                .append(threadTag())
                .append(" ")
                .append(clazzTag())
                .append(" : ")
                .append(content);
        System.out.println(sb.toString());
    }

    private String threadTag() {
        return "[" + Thread.currentThread().getName() + "]";
    }

    private String timeTag() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        return "[" + sdf.format(new Date()) + "]";
    }

    private String levelTag() {
        return "[ INFO]";
    }

    private String clazzTag() {
        return clazz.getName();
    }

}
